﻿#include"MenuAction.hpp"
templateItemWidget::templateItemWidget(itemWidget* item, QWidget* parent)
    :m_item(item), QWidgetAction(parent)
{
 
}


QWidget* templateItemWidget::createWidget(QWidget* parent)
{   
	m_item->setParent(parent);
	m_item->installEventFilter(this);
	return m_item;
}

bool templateItemWidget::eventFilter(QObject* obj, QEvent* event)
{
	if (obj == m_item)
	{
		
		if (event->type() == QEvent::Enter)
		{
	
			m_item->setStyleSheet("background-color: rgb(232, 235, 239);border: none;spacing: 1px;border-radius: 2px;");
		}
		if (event->type() == QEvent::Leave)
		{
			m_item->setStyleSheet("background-color:rgb(255, 255, 255);border: none;spacing: 1px;border-radius: 2px; ");
		}
		if (event->type() == QEvent::Show)
		{
			m_item->setStyleSheet("background-color: white; border: none; spacing: 1px; border-radius: 2px;");
		}
		if (event->type() == QEvent::MouseButtonPress)
		{
			m_item->onClick();
		}
		if (event->type() == QEvent::FocusIn)
		{
		}
		if (event->type() == QEvent::FocusOut)
		{
			//焦点离开
		}
	}
	return QWidgetAction::eventFilter(obj, event);
}
